package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.StockBackService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SkuBackConsumer {

    @Autowired
    private StockBackService stockBackService;

    @RabbitListener(queues = "queue.skuback")
    public void onMessage(Message message) {
        try {
            String orderItemList = new String(message.getBody());
            List<OrderItem> orderItems = JSON.parseArray(orderItemList, OrderItem.class);
            stockBackService.addList(orderItems);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
